package cs275.ants.shared;

import junit.framework.TestCase;

public class CycleFreeStackTest extends TestCase {

	Object item1; 
	Object item2;
	Object item3;
	Object item4;
	CycleFreeStack<Object> stack;
	
	protected void setUp() throws Exception {
		super.setUp();
		stack = new CycleFreeStack<Object>();
		item1 = new Object(); 
		item2 = new Object();
		item3 = new Object();
		item4 = new Object();
	}
	
	public void testPush() {

		assertEquals(stack.size(), 0);

		assertEquals(item1, stack.push(item1));
		assertEquals(stack.size(), 1);
		
		assertEquals(item1, stack.push(item1));
		assertEquals(stack.size(), 1);
	
		assertEquals(item2, stack.push(item2));
		assertEquals(stack.size(), 2);	
		assertEquals(item1, stack.elementAt(0));
		assertEquals(item2, stack.elementAt(1));
		// 1, 2 in stack 
		
		stack.push(item3);
		stack.push(item4); 
		assertEquals(4, stack.size()); 
		assertEquals(item1, stack.elementAt(0));
		assertEquals(item2, stack.elementAt(1));
		assertEquals(item3, stack.elementAt(2));
		assertEquals(item4, stack.elementAt(3));
		
		// 1, 2, 3, 4 in stack 
		assertEquals(item2, stack.push(item2));
		assertEquals(2, stack.size());
		assertEquals(item1, stack.elementAt(0));
		assertEquals(item2, stack.elementAt(1));
		
		// 1, 2 in stack 
		assertEquals(item1, stack.push(item1));
		assertEquals(1, stack.size());
		assertEquals(item1, stack.elementAt(0));
	}

	public void testClearElement() {
		stack.push(item1);
		stack.push(item2); 
		stack.push(item3);
		stack.push(item1);
		stack.push(item2);
		
		assertEquals(2, stack.size());
		assertEquals(item1, stack.elementAt(0));
		assertEquals(item2, stack.elementAt(1));
	}
}
